//------------------------------------------------------------------------------
// <copyright company="Telligent Systems">
//     Copyright (c) Telligent Systems Corporation.  All rights reserved.
// </copyright> 
//------------------------------------------------------------------------------

using System;
using System.ComponentModel;
using System.Web.UI.WebControls;
using CommunityServer.Components;
using CommunityServer.Files.Components;
using CommunityServer.Controls;

namespace CommunityServer.Files.Controls
{

	public class CategoryDetails : FileGalleryTemplatedWebControl
	{
		CSContext csContext = CSContext.Current;

		#region Child Controls

		private IText NameLabel;
		private IText DescriptionLabel;

		#endregion

		#region Public Properties

		[DefaultValue( "" )]
		public virtual string ApplicationKey
		{
			get
			{
				Object state = ViewState["ApplicationKey"];
				if(state != null)
					return (string)state;
				return "";
			}
			set { ViewState["ApplicationKey"] = value; }
		}

		[DefaultValue( 0 )]
		public virtual int CategoryID
		{
			get
			{
				Object state = ViewState["CategoryID"];
				if(state != null)
					return (int)state;
				return 0;
			}
			set { ViewState["CategoryID"] = value; }
		}

		#endregion

		#region Skin

		protected override void AttachChildControls()
		{
			NameLabel = FindText( "Name" );
			DescriptionLabel = FindText( "Description" );
		}

		#endregion

		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			ApplicationKey = csContext.ApplicationKey;
			CategoryID = csContext.CategoryID;
		}

		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			this.DataBind();
		}

		public override void DataBind()
		{
			base.DataBind();

			PostCategory category = PostCategories.GetCategory(CategoryID, Folders.GetFolderID(ApplicationKey));

			if (NameLabel != null)
				NameLabel.Text = category.Name;

			if (DescriptionLabel != null)
				DescriptionLabel.Text = category.Description.Replace("\n", "<br/>");
		}

	}
}
